package com.jstide.credit.data.service.biz;

import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import com.jstide.credit.data.service.Algorithm;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.util.List;
import java.util.Optional;

public class Factor34 extends Algorithm {

    private static final Logger logger = LoggerFactory.getLogger(Factor34.class);

    @Getter
    public final  String name="34";

    //其他公益信息
    //计次，一次给10分，最高50分，取值3年内
    //50
    @Getter
    public  final String sql = " select  count(1)  as TOTAL from ZRRQTGYXX where join_id=@joinId and RDRQ >  trunc(sysdate)-(INTERVAL '3' YEAR)  ";
    @Getter
    public final int defaultScore=10;

    private final int maxScore=50;

    @Override
    public int translate(String rs) {
        return 0;
    }



    @Override
    public int translate(List<Entity> rs) {
        int result =0;
        try {
            int total =0;
            if(null!=rs && rs.size()>0){
                total =  Optional.ofNullable(rs.get(0).getInt("TOTAL")).orElse(0);
            }
            result = total>0? defaultScore*total:0; ;
            result = result>maxScore?maxScore:result;
        }
        catch (Exception e){
            logger.error(StrUtil.format("项目{}计算错误：",name),e);
        }
        return result;
    }
}
